package com.atguigu.gulimail.product.web;

import com.atguigu.gulimail.product.entity.CategoryEntity;
import com.atguigu.gulimail.product.service.CategoryService;
import com.atguigu.gulimail.product.vo.Catalog2Vo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Auther: tianchao
 * @Date: 2021/1/17 11:22
 * @Description:
 */
@Controller
@Slf4j
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/","index.html"})
    public String indexPage(Model model){
        List<CategoryEntity> categories = categoryService.getLevel1Categories();
        model.addAttribute("categories", categories);
        log.debug("[去index页面]");
        return "index";
    }
    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catalog2Vo>> getCatelogJson(){
        return categoryService.getCatalogJson();
    }
}
